
module.exports = {
    channelDayTotalExcel1: async function(datas){
        // console.log(datas);
        let channelObj = {};
        channelObj.rows = [];
        let time;
        for(var index in datas){
            var account = datas[index];
            var data = [] ;
            if(index == 0) {
                channelObj.cols = [
                    {caption: '渠道名称', type: 'string'},
                    {caption: '统计日期', type: 'string'},
                    {caption: '注册用户数', type: 'number', width:12},
                    {caption: '渠道用户数', type: 'number'},
                    {caption: '百分比', type: 'number'},
                    {caption: '次日留存用户数', type: 'number', width:16},
                    {caption: '三日留存用户数', type: 'number', width:16},
                    {caption: '导出数量', type: 'number'},
                    {caption: '新用户导出数量', type: 'number', width:16},
                    {caption: '视频看完数量', type: 'number', width:14},
                    {caption: '新用户视频看完数量', type: 'number', width:20}
                ];
            }
            let {channelName,addDate,registerUserCount,channelUserCount,precent,nextDayCount,threeDayCount,openCount,newUserOpenCount,videoCount,newUserVideoCount} = account;
            data = [channelName,addDate,registerUserCount,channelUserCount,precent,nextDayCount,threeDayCount,openCount,newUserOpenCount,videoCount,newUserVideoCount];
            channelObj.rows.push(data);
            time = addDate;
        }
        let result = await this.writeXls(channelObj);
        return {result, addDate: time};
    },
    channelDayTotalExcel2: async function(datas){
        // console.log(datas);
        let channelObj = {};
        channelObj.rows = [];
        let time;
        for(var index in datas){
            var account = datas[index];
            var data = [] ;
            if(index == 0) {
                channelObj.cols = [
                    {caption: '渠道名称', type: 'string'},
                    {caption: '统计日期', type: 'string'},
                    {caption: '注册用户数', type: 'number', width:12},
                    // {caption: '渠道用户数', type: 'number'},
                    // {caption: '百分比', type: 'number'},
                    {caption: '渠道跳转用户总数', type: 'number', width:18},
                    {caption: '注册用户占比', type: 'number', width:14},
                    {caption: '结算比例', type: 'number'},
                    {caption: '最新结算比例', type: 'number', width:14},
                    // {caption: '渠道百分比', type: 'number', width:12},
                    // {caption: '计价用户', type: 'number'},
                    {caption: '结算用户', type: 'number'},
                    {caption: '修改后结算', type: 'number'},
                    {caption: '次日留存用户数', type: 'number', width:16},
                    {caption: '三日留存用户数', type: 'number', width:16},
                    {caption: '导出数量', type: 'number'},
                    {caption: '新用户导出数量', type: 'number', width:16},
                    {caption: '视频看完数量', type: 'number', width:14},
                    {caption: '新用户视频看完数量', type: 'number', width:20}
                ];
            }
            let {channelName,addDate,registerUserCount,channelUserCount,channelUserCountAfter,precent,navigateUserCount,registerUserPer,settlementPer,nowPercent,channelPer,priceUser,settlementUser,nextDayCount,threeDayCount,openCount,newUserOpenCount,videoCount,newUserVideoCount} = account;
            data = [channelName,addDate,registerUserCount,/*channelUserCount,precent,*/navigateUserCount,registerUserPer,settlementPer,nowPercent,channelUserCount,channelUserCountAfter,nextDayCount,threeDayCount,openCount,newUserOpenCount,videoCount,newUserVideoCount];
            channelObj.rows.push(data);
            time = addDate;
        }
        let result = await this.writeXls(channelObj);
        return {result, addDate: time};
    },

    totalListExcel: async function(datas, addDate){
        // console.log(datas);
        let obj = {};
        obj.rows = [];
        obj.cols = [];
        for(var index in datas){
            var account = datas[index];
            var data = [] ;
            if(index == 0) {
                obj.cols = [
                    {caption: '游戏名称', type: 'string'},
                    {caption: '点击量', type: 'number'},
                    {caption: '打开量', type: 'number'},
                    {caption: '点击量去重', type: 'number', width:12},
                    {caption: '打开量去重', type: 'number', width:12},
                    {caption: '导出数', type: 'number', width:12},
                    {caption: '卖量单价', type: 'number', width:12},
                    {caption: '导出收益', type: 'number', width:12},
                    {caption: '点击去重金额', type: 'number', width:16},
                ];
            }
            let {count, newCount, openCount, newOpenCount, exportCount, sellPrice, exportProfit, clickProfit} = account;
            let appName = addDate == new Date().toLocaleDateString() ? account._id : account.appName;
            data = [appName, count, openCount, newCount, newOpenCount, exportCount, sellPrice, exportProfit, clickProfit];
            obj.rows.push(data);
        }
        let result = await this.writeXls(obj);
        return {result, addDate};
    },

    detailListExcel: async function(datas){
        // console.log(datas);
        let obj = {};
        obj.rows = [];
        obj.cols = [];
        let time;
        for(var index in datas){
            var account = datas[index];
            var data = [] ;
            if(index == 0) {
                obj.cols = [
                    {caption: '游戏名称', type: 'string'},
                    {caption: '场景名称', type: 'string'},
                    {caption: '位置', type: 'number'},
                    {caption: '日期', type: 'string'},
                    {caption: '点击量', type: 'number'},
                    {caption: '点击量去重', type: 'number', width:12},
                    {caption: '打开量', type: 'number'},
                    {caption: '打开量去重', type: 'number', width:12},
                ];
            }
            let {appName, sceneName, area, addDate, count, newCount, openCount, newOpenCount} = account;
            data = [appName, sceneName, area, addDate, count, newCount, openCount, newOpenCount];
            obj.rows.push(data);
            time = addDate;
        }
        let result = await this.writeXls(obj);
        return {result, addDate: time};
    },
    writeXls: async function(datas){
        let nodeExcel = require('excel-export');
        let result = nodeExcel.execute(datas);
        // let result = null;
        return result
    },

};